package com.jubao.ejb.business.impl;

import java.util.List;

import javax.ejb.Stateless;

import org.jboss.ejb3.annotation.LocalBinding;
import org.jboss.ejb3.annotation.RemoteBinding;

import com.jubao.ejb.business.Business;
import com.jubao.ejb.business.CategoryBusinessLocal;
import com.jubao.ejb.business.CategoryBusinessRemote;
import com.jubao.ejb.business.util.BusinessConstant;
import com.jubao.ejb.entity.Brand;
import com.jubao.ejb.entity.Category;

@Stateless
@LocalBinding(jndiBinding = BusinessConstant.CategoryBusinessLocalJndiName)
@RemoteBinding(jndiBinding = BusinessConstant.CategoryBusinessRemoteJndiName)
public class CategoryBusinessImpl extends Business implements CategoryBusinessLocal, CategoryBusinessRemote {

	/* (non-Javadoc)
	 * @see com.jubao.ejb.business.CategoryBusiness#getCategoryRelatedBrands(long)
	 */
	public List<Brand> getCategoryBrands(long categorySysId) {
		List brands = super.geneRelationDao.getEntityList(Brand.class.getName(),
				BusinessConstant.RelationID.BRAND_IS_BRANDER_OF_CATEGORY.getId(), categorySysId, 0, 100);
		if(brands == null || brands.size()==0){
			Category cat = categoryDao.find(categorySysId);
			Category pcat = cat.getPrimaryParent();
			if(pcat!=null){				
				brands = getCategoryBrands(pcat.getSysId());
			}
		}

		return brands;
	}

}
